package com.dlc.felear.xiaoensale.customView;

import android.content.Context;
import android.view.View;
import android.widget.Button;

import com.dlc.felear.xiaoensale.R;

public class BtnTableUtil implements View.OnClickListener {
    private Context context;
    private Button btn1, btn2;
    private BtnSelectCallball callball;

    public void setCallball(BtnSelectCallball callball) {
        this.callball = callball;
    }

    public BtnTableUtil(Context context, Button btn1, Button btn2) {
        this.context = context;
        this.btn1 = btn1;
        this.btn2 = btn2;
        initView();
    }

    private void initView() {
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        setBtnBg(view.getId());
    }

    public void setBtnBg(int id) {
        btn1.setBackgroundColor(context.getResources().getColor(R.color.wx_btn_unselect_color));
        btn2.setBackgroundColor(context.getResources().getColor(R.color.wx_btn_unselect_color));
        switch (id) {
            case R.id.btn_wx_table_1:
                btn1.setBackgroundColor(context.getResources().getColor(R.color.wx_btn_select_color));
                if (callball != null) {
                    callball.btnSelect(0);
                }
                break;
            case R.id.btn_wx_table_2:
                btn2.setBackgroundColor(context.getResources().getColor(R.color.wx_btn_select_color));
                if (callball != null) {
                    callball.btnSelect(1);
                }
                break;
        }
    }

    public interface BtnSelectCallball {
        void btnSelect(int position);
    }

}
